]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
gnome-shell-jhbuild: Fix race condition when launching DConf manually
authorOwen W. Taylor <otaylor@fishsoup.net>
Tue, 8 Mar 2011 23:04:34 +0000 (18:04 -0500)
committerOwen W. Taylor <otaylor@fishsoup.net>
Sat, 12 Mar 2011 00:21:06 +0000 (19:21 -0500)
We need to connect to the NameOwnerChanged signal before we execute the
DConf binary. Refactor things so that we connect to the signal when
we first get the bus object. Split the code for waiting for a D-Bus
name into a wait_for_dbus_name() function for latter reuse.

https://bugzilla.gnome.org/show_bug.cgi?id=644265

src/gnome-shell-jhbuild.in

index f10a576ff009a6a4eb573c06b5252bfbc054eac0..54dfed862679123d6c60f4c84599cdb0d8d9bf19 100755 (executable)
@@ -79,11 +79,56 @@ def get_running_session_environs():
                 result[key] = environs[key]
         return result
 
+_bus = None
+_bus_iface = None
+_name_owner_changed_hook = None
+
+def on_name_owner_changed(name, prev_owner, new_owner):
+    if _name_owner_changed_hook:
+        _name_owner_changed_hook(name, prev_owner, new_owner)
+
+def get_bus():
+    global _bus
+    if _bus is None:
+        dbus_loop = DBusGMainLoop()
+        _bus = dbus.SessionBus(mainloop=dbus_loop)
+    return _bus
+
+def get_bus_iface():
+    global _bus_iface
+    if _bus_iface is None:
+        bus = get_bus()
+        bus_proxy = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
+        _bus_iface = dbus.Interface(bus_proxy, 'org.freedesktop.DBus')
+        _bus_iface.connect_to_signal('NameOwnerChanged', on_name_owner_changed)
+    return _bus_iface
+
+def wait_for_dbus_name(wait_name):
+    global _name_owner_changed_hook
+
+    bus_iface = get_bus_iface()
+    loop = gobject.MainLoop()
+
+    def on_name_owner_changed(name, prev_owner, new_owner):
+        if not (name == wait_name and new_owner != ''):
+            return
+        loop.quit()
+        return
+    _name_owner_changed_hook = on_name_owner_changed
+
+    def on_timeout():
+        print "\nFailed to start %s: timed out" % (wait_name,)
+        sys.exit(1)
+    gobject.timeout_add_seconds(7, on_timeout)
+
+    loop.run()
+    _name_owner_changed_hook = None
+
 def start_dconf_await_service():
     DCONF_NAME = 'ca.desrt.dconf'
 
-    dbus_loop = DBusGMainLoop()
-    bus = dbus.SessionBus(mainloop=dbus_loop)
+    bus = get_bus()
+    get_bus_iface() # connect to NameOwnerChanged signal
 
     # See if the service is already running or normal D-Bus activation works
     need_manual_activate = False
@@ -122,25 +167,7 @@ def start_dconf_await_service():
         print "\nFailed to start %s: %s" % (dconf_path, e)
         sys.exit(1)
 
-    bus_proxy = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
-    bus_iface = dbus.Interface(bus_proxy, 'org.freedesktop.DBus')
-
-    loop = gobject.MainLoop()
-
-    def on_name_owner_changed(name, prev_owner, new_owner):
-        if not (name == DCONF_NAME and new_owner != ''):
-            return
-        print "started"
-        loop.quit()
-        return
-    bus_iface.connect_to_signal('NameOwnerChanged', on_name_owner_changed)
-
-    def on_timeout():
-        print "\nFailed to start %s: timed out" % (dconf_path,)
-        sys.exit(1)
-    gobject.timeout_add_seconds(7, on_timeout)
-
-    loop.run()
+    wait_for_dbus_name (DCONF_NAME)
 
 def start_shell(perf_output=None):
     self_dir = os.path.dirname(os.path.abspath(sys.argv[0]))